package com.cleaningcloud.erp.controller.mini;

import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.api.domain.ErpCommodity;
import com.cleaningcloud.erp.domain.ErpCommodityType;
import com.cleaningcloud.erp.domain.dto.ErpCommodityDto;
import com.cleaningcloud.erp.domain.vo.ErpCommodityVo;
import com.cleaningcloud.erp.service.IErpCommodityService;
import com.cleaningcloud.erp.service.IErpCommodityTypeService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 获取商品列表 - 小程序接口
 */
@RestController
@RequestMapping("/mini/commodity")
public class MiniCommodityController extends BaseController {

    @Autowired
    private IErpCommodityService commodityService;

    @Autowired
    private IErpCommodityTypeService commodityTypeService;

    @Operation(description = "查询商品记录")
    @GetMapping("/getCommodityList")
    public TableDataInfo getCommodityList(ErpCommodityDto erpCommodityDto){
        erpCommodityDto.getParams().putIfAbsent("wareId", erpCommodityDto.getWareId());
        startPage();
        List<ErpCommodityVo> list = commodityService.selectErpCommodityList(erpCommodityDto);
        return getMiniDataTable(list);
    }

    /**
     * 查询商品类型管理列表
     */
    @GetMapping("/getCommodityTypeList")
    public AjaxResult getCommodityTypeList(ErpCommodityType erpCommodityType)
    {
        List<ErpCommodityType> list = commodityTypeService.selectErpCommodityTypeList(erpCommodityType);
        return success(list);
    }
}
